<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Add a task to get status</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.addtasklowbackground.html">GearmanClient::addTaskLowBackground</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.clearcallbacks.html">GearmanClient::clearCallbacks</a></div>
 <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="gearmanclient.addtaskstatus" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">GearmanClient::addTaskStatus</h1>
  <p class="verinfo">(PECL gearman &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">GearmanClient::addTaskStatus</span> &mdash; <span class="dc-title">Add a task to get status</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-gearmanclient.addtaskstatus-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="class.gearmantask.html" class="type GearmanTask">GearmanTask</a></span> <span class="methodname"><strong>GearmanClient::addTaskStatus</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$job_handle</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$context</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Used to request status information from the Gearman server, which will call the specified
   status callback (set using <span class="methodname"><a href="gearmanclient.setstatuscallback.html" class="methodname">GearmanClient::setStatusCallback()</a></span>).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-gearmanclient.addtaskstatus-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">job_handle</code></em></dt>

     <dd>

      <p class="para">
       The job handle for the task to get status for
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">context</code></em></dt>

     <dd>

      <p class="para">
       Data to be passed to the status callback, generally a reference to an array or object
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-gearmanclient.addtaskstatus-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   A <a href="class.gearmantask.html" class="classname">GearmanTask</a> object.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-gearmanclient.addtaskstatus-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4227">
    <p><strong>Example #1 Monitor completion of multiple background tasks</strong></p>
    <div class="example-contents"><p>
     An artificial delay is introduced in the worker in this example to simulate
     a long running process. There is only one worker running for this example.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;create&nbsp;our&nbsp;object&nbsp;*/<br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">GearmanClient</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;add&nbsp;the&nbsp;default&nbsp;server&nbsp;*/<br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;start&nbsp;some&nbsp;background&nbsp;jobs&nbsp;and&nbsp;save&nbsp;the&nbsp;handles&nbsp;*/<br /></span><span style="color: #0000BB">$handles&nbsp;</span><span style="color: #007700">=&nbsp;array();<br /></span><span style="color: #0000BB">$handles</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">doBackground</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;World!"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$handles</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">doBackground</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"!dlroW&nbsp;olleH"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStatusCallback</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse_status"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Poll&nbsp;the&nbsp;server&nbsp;to&nbsp;see&nbsp;when&nbsp;those&nbsp;background&nbsp;jobs&nbsp;finish;&nbsp;*/<br />/*&nbsp;a&nbsp;better&nbsp;method&nbsp;would&nbsp;be&nbsp;to&nbsp;use&nbsp;event&nbsp;callbacks&nbsp;*/<br /></span><span style="color: #007700">do<br />{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Use&nbsp;the&nbsp;context&nbsp;variable&nbsp;to&nbsp;track&nbsp;how&nbsp;many&nbsp;tasks&nbsp;have&nbsp;completed&nbsp;*/<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$done&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addTaskStatus</span><span style="color: #007700">(</span><span style="color: #0000BB">$handles</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">],&nbsp;&amp;</span><span style="color: #0000BB">$done</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addTaskStatus</span><span style="color: #007700">(</span><span style="color: #0000BB">$handles</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">],&nbsp;&amp;</span><span style="color: #0000BB">$done</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">runTasks</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Done:&nbsp;</span><span style="color: #0000BB">$done</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />}<br />while&nbsp;(</span><span style="color: #0000BB">$done&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br />function&nbsp;</span><span style="color: #0000BB">reverse_status</span><span style="color: #007700">(</span><span style="color: #0000BB">$task</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$done</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$task</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isKnown</span><span style="color: #007700">())<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$done</span><span style="color: #007700">++;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 0
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 1
Done: 2
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-gearmanclient.addtaskstatus-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="gearmanclient.setstatuscallback.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::setStatusCallback()</a> - Set a callback for collecting task status</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.addtasklowbackground.html">GearmanClient::addTaskLowBackground</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.clearcallbacks.html">GearmanClient::clearCallbacks</a></div>
 <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
